﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GrouponDesktop;
using System.Data.SqlClient;

namespace GrouponDesktop.MenuPrincipal
{
    public partial class MenuPrincipal : Form
    {
        private int userID;
        private int idCli;
        private int cred;
        private int idProv;

        public MenuPrincipal(int id)
        {


            
            this.userID = id;
            this.idCli = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDCli '" + this.userID + "'");
            cred = BDConnection.QueryAndExecuteScalar("select CodingSpree.calcular_credito (" + this.idCli + ")");
            
            InitializeComponent();
            int rol = BDConnection.QueryAndExecuteScalar("select Rol from CodingSpree.TL_USUARIOS where id_general = '" + this.userID + "'");
            
            
            if (rol == 3)
            {
                b_abmProv.Hide();
                b_abmCli.Hide();
                b_abmAdmin.Hide();
                b_cargaCred.Hide();
                b_compCupon.Hide();
                b_compGC.Hide();
                b_pedDevo.Hide();
                b_historial.Hide();
                b_pubCupon.Hide();
                b_armarCupon.Hide();
                b_listado.Hide();
                b_facturar.Hide();
                l_abmCli.Hide();
                l_abmProv.Hide();
                l_admin.Hide();
                l_compCred.Hide();
                l_compCup.Hide();
                l_compGC.Hide();
                l_pedDev.Hide();
                l_hist.Hide();
                l_pubCup.Hide();
                l_armarCup.Hide();
                l_listarEstad.Hide();
                l_factProv.Hide();
                b_regCup.Hide();
                l_regCup.Hide();
                label5.Hide();
                tb_cred.Hide();
                b_ref.Hide();
                b_exit.Show();
                
            }
            else
            {

                b_abms.Hide();
                b_client.Hide();
                b_prove.Hide();
                b_fact.Hide();
                b_abmProv.Hide();
                b_abmCli.Hide();
                b_abmAdmin.Hide();
                b_cargaCred.Hide();
                b_compCupon.Hide();
                b_compGC.Hide();
                b_pedDevo.Hide();
                b_historial.Hide();
                b_pubCupon.Hide();
                b_armarCupon.Hide();
                b_listado.Hide();
                b_facturar.Hide();
                label1.Hide();
                label2.Hide();
                label3.Hide();
                label4.Hide();
                l_abmCli.Hide();
                l_abmProv.Hide();
                l_admin.Hide();
                l_compCred.Hide();
                l_compCup.Hide();
                l_compGC.Hide();
                l_pedDev.Hide();
                l_hist.Hide();
                l_pubCup.Hide();
                l_armarCup.Hide();
                l_listarEstad.Hide();
                l_factProv.Hide();
                b_regCup.Hide();
                l_regCup.Hide();
                label5.Hide();
                tb_cred.Hide();
                b_ref.Hide();
                b_exit.Hide();

                string Query = "EXEC CodingSpree.listarFunxRol " + rol;

                                
                SqlDataReader myReader2 = BDConnection.QueryAndExecute(Query);

                while (myReader2.Read())
                {

                    if ((int)myReader2["id_funcionalidad"] == 1)
                    {
                        b_abmAdmin.Show();
                        l_admin.Show();
                    }
                    if ((int)myReader2["id_funcionalidad"] == 2)
                    {
                        b_abmProv.Show();
                        l_abmCli.Show();
                    }
                    if ((int)myReader2["id_funcionalidad"] == 3)
                    {
                        b_abmCli.Show();
                        l_abmProv.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 4)
                    {
                        b_exit.Show();
                        
                        b_armarCupon.Show();
                        l_armarCup.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 5)
                    {
                        b_regCup.Show();
                        l_regCup.Show();
                    }


                    if ((int)myReader2["id_funcionalidad"] == 6)
                    {
                        b_cargaCred.Show();
                        l_compCred.Show();
                        tb_cred.Show();
                        label5.Show();
                        b_ref.Show();
                        b_exit.Show();
                        tb_cred.Text = cred.ToString();
                        
                    }

                    if ((int)myReader2["id_funcionalidad"] == 7)
                    {
                        b_compGC.Show();
                        l_compGC.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 8)
                    {
                        b_compCupon.Show();
                        l_compCup.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 9)
                    {
                        b_pedDevo.Show();
                        l_pedDev.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 10)
                    {
                        b_historial.Show();
                        l_hist.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 11)
                    {
                        b_pubCupon.Show();
                        l_pubCup.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 12)
                    {
                        b_facturar.Show();
                        l_factProv.Show();
                    }

                    if ((int)myReader2["id_funcionalidad"] == 13)
                    {
                        b_listado.Show();
                        l_listarEstad.Show();
                    }

                }

                myReader2.Close();
            }


           
        
        }



        private void b_abms_Click(object sender, EventArgs e)
        {
            l_abmCli.Show();
            l_abmProv.Show();
            l_admin.Show();
            l_compCred.Hide();
            l_compCup.Hide();
            l_compGC.Hide();
            l_pedDev.Hide();
            l_hist.Hide();
            l_pubCup.Hide();
            l_armarCup.Hide();
            l_listarEstad.Hide();
            l_factProv.Hide();
            b_abmProv.Show();
            b_abmCli.Show();
            b_abmAdmin.Show();
            b_cargaCred.Hide();
            b_compCupon.Hide();
            b_compGC.Hide();
            b_pedDevo.Hide();
            b_historial.Hide();
            b_pubCupon.Hide();
            b_armarCupon.Hide();
            b_listado.Hide();
            b_facturar.Hide();
            b_regCup.Hide();
            l_regCup.Hide();

        }

        private void b_client_Click(object sender, EventArgs e)
        {
            l_abmCli.Hide();
            l_abmProv.Hide();
            l_admin.Hide();
            l_compCred.Show();
            l_compCup.Show();
            l_compGC.Show();
            l_pedDev.Show();
            l_hist.Show();
            l_pubCup.Hide();
            l_armarCup.Hide();
            l_listarEstad.Hide();
            l_factProv.Hide();
            l_regCup.Hide();

            b_abmProv.Hide();
            b_abmCli.Hide();
            b_abmAdmin.Hide();
            b_cargaCred.Show();
            b_compCupon.Show();
            b_compGC.Show();
            b_pedDevo.Show();
            b_historial.Show();
            b_pubCupon.Hide();
            b_armarCupon.Hide();
            b_listado.Hide();
            b_facturar.Hide();
            b_regCup.Hide();
        }


        private void b_prove_Click(object sender, EventArgs e)
        {
            l_abmCli.Hide();
            l_abmProv.Hide();
            l_admin.Hide();
            l_compCred.Hide();
            l_compCup.Hide();
            l_compGC.Hide();
            l_pedDev.Hide();
            l_hist.Hide();
            l_pubCup.Hide();
            l_armarCup.Show();
            l_listarEstad.Hide();
            l_factProv.Hide();
            l_regCup.Show();

            b_abmProv.Hide();
            b_abmCli.Hide();
            b_abmAdmin.Hide();
            b_cargaCred.Hide();
            b_compCupon.Hide();
            b_compGC.Hide();
            b_pedDevo.Hide();
            b_historial.Hide();
            b_pubCupon.Hide();
            b_armarCupon.Show();
            b_listado.Hide();
            b_facturar.Hide();
            b_regCup.Show();

        }

        private void b_fact_Click(object sender, EventArgs e)
        {
            l_abmCli.Hide();
            l_abmProv.Hide();
            l_admin.Hide();
            l_compCred.Hide();
            l_compCup.Hide();
            l_compGC.Hide();
            l_pedDev.Hide();
            l_hist.Hide();
            l_pubCup.Show();
            l_armarCup.Hide();
            l_listarEstad.Show();
            l_factProv.Show();
            l_regCup.Hide();

            b_abmProv.Hide();
            b_abmCli.Hide();
            b_abmAdmin.Hide();
            b_cargaCred.Hide();
            b_compCupon.Hide();
            b_compGC.Hide();
            b_pedDevo.Hide();
            b_historial.Hide();
            b_pubCupon.Show();
            b_armarCupon.Hide();
            b_listado.Show();
            b_facturar.Show();
            b_regCup.Hide();
        }

        // BOTONES DE ABM
        private void b_abmAdmin_Click(object sender, EventArgs e)
        {
            GrouponDesktop.ABMrol abmrol = new ABMrol();
            abmrol.Show();
        }

        private void b_abmCli_Click(object sender, EventArgs e)
        {
            GrouponDesktop.AbmCliente.ABMclient abmcli = new AbmCliente.ABMclient();
            abmcli.Show();
        }

        private void b_abmProv_Click(object sender, EventArgs e)
        {
            GrouponDesktop.AbmProveedor.ABMProvee abmprov = new AbmProveedor.ABMProvee();
            abmprov.Show();
        }

        // BOTONES PARA CLIENTES!

        private void b_compGC_Click(object sender, EventArgs e)
        {
            //idCli = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDCli '" + this.userID + "'");
            ComprarGiftCard.ComprarGC CGC = new ComprarGiftCard.ComprarGC(idCli);
            CGC.Show();
        }


        private void b_cargaCred_Click(object sender, EventArgs e)
        {
            //idCli = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDCli '" + this.userID + "'");
            CargaCredito.CargarCred CC = new CargaCredito.CargarCred(this.idCli);
            CC.Show();
        }

        private void b_historial_Click(object sender, EventArgs e)
        {
            //idCli = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDCli '" + this.userID + "'");
            HistorialCupones.HistorialCupones HC = new HistorialCupones.HistorialCupones(idCli);
            HC.Show();
        }

        private void b_compCupon_Click(object sender, EventArgs e)
        {
            //idCli = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDCli '" + this.userID + "'");
            ComprarCupon.ComprarCup CC = new ComprarCupon.ComprarCup(this.idCli);
            CC.Show();

        }

        private void b_pedDevo_Click(object sender, EventArgs e)
        {
            PedirDevolucion.PedirDevo PD = new PedirDevolucion.PedirDevo(this.idCli);
            PD.Show();
        }

        //FIN BOTONES PARA CLIENTES


        // BOTONES PARA PROVEEDORES
        private void b_armarCupon_Click(object sender, EventArgs e)
        {
            this.idProv = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDProv '" + this.userID + "'");
            GrouponDesktop.ArmarCupon.ArmarCupon AC = new ArmarCupon.ArmarCupon(this.idProv);
            AC.Show();
        }

        private void b_regCup_Click(object sender, EventArgs e)
        {
            this.idProv = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDProv '" + this.userID + "'");
            RegistroConsumoCupon.RegistroConsumoCup RC = new RegistroConsumoCupon.RegistroConsumoCup(idProv);
            RC.Show();
        }

        
        // BOTONES PARA ADMINISTRATIVOS
        private void b_pubCupon_Click(object sender, EventArgs e)
        {
            PublicarCupon.pubCupon PC = new PublicarCupon.pubCupon();
            PC.Show();
        }

        private void b_facturar_Click(object sender, EventArgs e)
        {
            this.idProv = BDConnection.QueryAndExecuteScalar("EXEC CodingSpree.getIDProv '" + this.userID + "'");
            FacturarProveedor.factProv FP = new FacturarProveedor.factProv();
            FP.Show();
        }

        private void b_listado_Click(object sender, EventArgs e)
        {
            ListadoEstadistico.ListadoEstadist LE = new ListadoEstadistico.ListadoEstadist();
            LE.Show();
        }

        private void MenuPrincipal_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            tb_cred.Text = BDConnection.QueryAndExecuteScalarString("select CodingSpree.calcular_credito (" + this.idCli + ")");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MenuLogin ml = new MenuLogin();
            ml.Show();
            this.Hide();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            NuevaContraseña NC = new NuevaContraseña(this.userID);
            NC.Show();
        }

    }
}

